package wangjg.coco.views;

import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.jface.preference.RadioGroupFieldEditor;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
import org.eclipse.ui.internal.WorkbenchImages;

import wangjg.coco.Activator;

public class PreferencePassPolicyPage extends FieldEditorPreferencePage
		implements IWorkbenchPreferencePage {
	public static final String PASSWORD_CHARS = "passgate.password.chars";
	public static final String ALPHABETIC = "alphabetic";
	public static final String ALPHANUMERIC = "alphanumeric";
	public static final String NUMERIC = "numeric";
	public static final String PASSWORD_CASE = "passgate.password.case";
	public static final String UPPER = "uppercase";
	public static final String LOWER = "lowercase";
	public static final String MIXED = "mixed";
	public static final String PASSWORD_LENGTH = "passgate.password.length";

	public PreferencePassPolicyPage() {
		super(GRID);
		setTitle("Password Policy");
		ImageDescriptor imgDes = WorkbenchImages.getImageDescriptor(IWorkbenchGraphicConstants.IMG_DTOOL_NEW_FASTVIEW);
		setImageDescriptor(imgDes);
		setPreferenceStore(Activator.getDefault().getPreferenceStore());
	}

	public void init(IWorkbench workbench) {
	}

	protected void createFieldEditors() {
		// characters
		String[][] choose = new String[][] {
				new String[] { "Use alphabetic only", ALPHABETIC },
				new String[] { "Use numberic only", NUMERIC },
				new String[] { "Use alphanumeric only", ALPHANUMERIC } };
		FieldEditor charcterEditor = new RadioGroupFieldEditor(PASSWORD_CHARS,
				"Characters", 1, choose, getFieldEditorParent(), true);
		addField(charcterEditor);

		// case
		choose = new String[][] { new String[] { "Lower case", LOWER },
				new String[] { "Upper case", UPPER },
				new String[] { "Mixed", MIXED } };
		FieldEditor caseEditor = new RadioGroupFieldEditor(PASSWORD_CASE,
				"Case", 1, choose, getFieldEditorParent(), true);
		addField(caseEditor);

		FieldEditor lengthEditor = new IntegerFieldEditor(PASSWORD_LENGTH,
				"Password length", getFieldEditorParent());
		addField(lengthEditor);
	}
}
